﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Enough.Lifecycle.Common
{
    public class NavigationParameterDictionary
    {
        private static NavigationParameterDictionary _current;
        public static NavigationParameterDictionary Current
        {
            get
            {
                NavigationParameterDictionary current = _current;
                if (current == null)
                {
                    current = new NavigationParameterDictionary();
                    _current = current;
                }
                return current;
            }
        }

        private Dictionary<Type, Object> _parameterDictionary = new Dictionary<Type, object>();
        private NavigationParameterDictionary()
        {
        }

        public void AddParameter(object value)
        {
            _parameterDictionary[value.GetType()] = value;
        }

        public T GetParameter<T>()
        {
            Type type = typeof(T);
            if (!_parameterDictionary.ContainsKey(type))
            {
                return default(T);
            }
            return (T)_parameterDictionary[type];
        }
    }
}
